<?
class SIGNUP
{
    private $user_id       = 0;
    private $user_name     = 0;
    private $mixi_id       = 0;
    private $facebook_id   = 0;
    private $twitter_id    = 0;
    private $c2dm_id       = 0;
    private $profile_image = 0;
    private $g_session     = 0;
    private $expire        = 0;

    function get_user_id()
    {
        return $this->user_id;
    }

    function get_mixi_id()
    {
        return $this->mixi_id;
    }

    function get_facebook_id()
    {
        return $this->facebook_id;
    }

    function get_twitter_id()
    {
        return $this->twitter_id;
    }

    function get_c2dm_id()
    {
        return $this->c2dm_id;
    }

    function get_user_name()
    {
        return $this->user_name;
    }

    function get_profile_image()
    {
        return $this->profile_image;
    }

    function get_g_session()
    {
        return $this->g_session;
    }

    function get_expire()
    {
        return $this->expire;
    }

    function load_user($member_id, $type = "UID")
    {
        switch($type)
        {
            case 'mixi':
                $where_column = "mixi_id";
            break;

            default:
                $where_column = "user_id";
            break;
        }

        $db = new DB_GEAR();

        //set query
        $aQuery['Type']   = 'select';
        $aQuery['Column'] = array('*');
        $aQuery['Table']  = 'garden_user_tbl';
        $aQuery['Where']  = $where_column.' = "'.$member_id.'"';

        //set query
        $db->set_query($aQuery);

        //send query
        $result = $db->send_query(1);

        //close DB
        $db->close_DB();

        if($result['cnt'] == 0)
        {
            return false;
        }
        else
        {
            $this->user_id       = $result[1]['user_id'];
            $this->user_name     = $result[1]['user_name'];
            $this->mixi_id       = $result[1]['mixi_id'];
            $this->facebook_id   = $result[1]['facebook_id'];
            $this->twitter_id    = $result[1]['twitter_id'];
            $this->c2dm_id       = $result[1]['c2dm_id'];
            $this->profile_image = $result[1]['profile_image'];
            return true;
        }
    }

    function register_user($member_id, $user_name, $profile_image = null, $type = 'mixi')
    {

        $db = new DB_GEAR();

        //set query
        $aQuery['Type'] = 'insert';
        $aQuery['Column'] = array(
                                'mixi_id'       => $member_id, 
                                'user_name'     => $user_name, 
                                'profile_image' => $profile_image,
                                );
        $aQuery['Table'] = 'garden_user_tbl';

        //set query
        $db->set_query($aQuery);
        
        //send query
        $result = $db->send_query(1);

        //close DB
        $db->close_DB();

        if($result['cnt'] == 0)
        {
            //echo 'NG';
            return false;
        }
        else
        {
            //echo 'OK';
            return true;
        }
    }

    /**
     * register_c2dm_id
     * Android C2DMサービスの登録IDをDBに保存します
     * @param {String} $registagion_id registaion id
     */
    function register_c2dm_id($member_id, $registation_id)
    {
        $db = new DB_GEAR();
        
        //set query
        $aQuery['Type']   = 'update';
        $aQuery['Column'] = array(
                                  'registation_id' => $registation_id
        );
        $aQuery['Where']  = 'user_id = '.$member_id;
        $aQuery['Table'] = 'garden_user_tbl';

        //set query
        $db->set_query($aQuery);
        //echo $db->get_query();

        //send query
        //echo $db->get_query();
        $result = $db->send_query(1);

        //close DB
        $db->close_DB();

        if($result['cnt'] == 0)
        {
            //echo 'NG';
            //return false;
        }
        else
        {
            //echo 'OK';
            //return true;
        }
    }

    function login($user_id)
    {
        $g_session = getRndID(1);
        $expire      = date("Y/m/d h:m:s",strtotime("+3 day"));
        
        $db = new DB_GEAR();
        
        //set query
        $aQuery['Type'] = 'replace into';
        $aQuery['Column'] = array(
                                'user_id' => $user_id, 
                                'session' => $g_session, 
                                'expire'  => $expire,
                                );
        $aQuery['Table'] = 'garden_login_tbl';

        //set query
        $db->set_query($aQuery);

        //send query
        $result = $db->send_query(1);

        //close DB
        $db->close_DB();

        if($result['cnt'] == -1)
        {
            //echo 'NG';
            return false;
        }
        else
        {
            //echo 'OK';
            $this->g_session = $g_session;
            $this->expire    = $expire;
            return true;
        }
    }

    function is_login($user_id, $g_session)
    {
        $db = new DB_GEAR();

        //set query
        $aQuery['Type'] = 'select';
        $aQuery['Column'] = array('*');
        $aQuery['Table'] = 'garden_login_tbl';
        $aQuery['Where'] = 'user_id ="'.$user_id.'" and session = "'.$g_session.'" and expire > NOW()';
        $db->set_query($aQuery);

        preDump($db->get_query());

        $result = $db->send_query(1);

        if($result['cnt'] == 1)
        {
        	//echo 'OK';
            return true;
        }
        else
        {
        	//echo 'NG';
            return false;
        }
    }

}
?>
